package org.spring.cloud.consul;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;

//./consul agent -server -ui -bootstrap-expect=1 -data-dir=/home/lisheng/consul/data -node=devmaster -advertise=192.168.1.24 -bind=0.0.0.0 -client=0.0.0.0
@EnableDiscoveryClient
@RestController
@SpringBootApplication
public class ConsulServiceApp {
	Gson g=new Gson();
	@Autowired
	private DiscoveryClient discoveryClient;

	@RequestMapping("/services")
	public Result services() {
		return new Result(true, g.toJson(discoveryClient.getServices()));
	}

	@RequestMapping("/home")
	public String home() {
		return "Hello World";
	}

	public static void main(String[] args) {
		SpringApplication.run(ConsulServiceApp.class, args);
	}
}
